<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]>      <html class="no-js"> <!--<![endif]-->
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
  </head>
  <body>
    <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
    ddddddddd
    ccccccc
    <p>rrrr</p>
    <h3>8888888</h3>
    <img src="./view.jpeg">
    <script>
      // 复制事件
      //把值设置到剪贴板中对象中，方便paste事件触发去拿e.clipboardData.setData("Text", copyMsg);}
      document.body.oncopy = e => {
        console.log(window.getSelection().toString())
        const copyMsg = window.getSelection().toString()
        e.clipboardData.setData("Text", copyMsg)
      }
     
      // 黏贴事件
      // document.body.oncopy = e => {
      //   console.log(window.getSelection().toString())
      //   let copyMsg = window.getSelection().toString()
      //   e.clipboardData.setData("Text", copyMsg)}
        
      //   document.body.onpaste=function(e){ 
      //     var data = e.clipboardData.getData("Text")
      //     document.querySelector("input").value = data}
      
      // 对于图片的复制 --- 对复制的对象啊进行遍历，然后通过type 进行判断
      // 对于图文混合， 可以将图片转成img, 然后拼成html 
      document.addEventListener('paste', function(event) { 
        var items = (event.clipboardData && event.clipboardData.items) || [];
        var file = null;
        if(items && items.length) { 
           for(var i = 0; i < items.length; i++) {
              if(items[i].type.indexOf('image') !== -1) { 
                file = items[i].getAsFile();
                break;
              }
           }
          }
      console.log(file)
    })

    </script>
  </body>
</html>